package cc.wsyw126.java.lambda;

import cc.wsyw126.java.model.User;
import org.junit.Assert;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by junpeng.yang on 16/9/22.
 */
public class TestElementOrder {
    public static List<User> getUserList(int n) {
        List<User> users = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            User user = new User();
            user.setName(i + "");
            users.add(user);
        }
        return users;
    }

    public void listOrder() {
        List<User> users = TestElementOrder.getUserList(5);
        List<User> sameUsers = users.stream().collect(Collectors.toList());

        Assert.assertEquals(users, sameUsers);
    }

    public void setOrder() {
        List list = TestElementOrder.getUserList(5);
        Set<User> users = new HashSet<>(list);
        Set<User> sameUsers = users.stream().collect(Collectors.toSet());

        Assert.assertEquals(users, sameUsers);

        //Assert.assertEquals(list,users.stream().collect(Collectors.toList()));错误的地方

    }

    public void intOrder() {
        List<Integer> list = Arrays.asList(4, 3, 25, 1);
        Set<Integer> set = new HashSet<>(list);


        Assert.assertEquals(list, set.stream().collect(Collectors.toList()));
    }

    public static void main(String[] args) {
//        TestElementOrder order = new TestElementOrder();
//        System.out.println("strat");
//        order.listOrder();
//
//        System.out.println("strat");
//        order.setOrder();
//
//        System.out.println("strat");
//        order.intOrder();

        List<String> list = new ArrayList<>();
        list.add("nihao");
        list.add("hao");

        list.add("hao");
        list.add("hao");
        list.add("hao");
        System.out.println(list);

        List<String> finalValues = list.stream().distinct().collect(Collectors.toList());
        System.out.println("finalValues = " + finalValues);

        list.removeAll(Arrays.asList("hao"));
        System.out.println("list = " + list);


    }
}
